package com.xja.controller;

import com.xja.bean.Users;
import com.xja.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UsersService usersService;
    //提交登录
    @RequestMapping("login")
    public String login(String name, String password, HttpSession session){
        try {
            System.out.println("进入登陆");
            Users users = usersService.sekectusername(name);
            try {
                if (users==null||!users.getName().equals(name)){
                    System.out.println("用户名错误");
                    return "login";
                }
                if (!users.getPassword().equals(password)||password==null){
                    System.out.println("密码错误");
                    return "login";
                }
                session.setAttribute("users",users);

                return "redirect:/house/selectAllHouse";
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    @RequestMapping("register")
    public String register(Users users){

            usersService.insertSelective(users);

        return "login";
    }

}
